package com.ymatou.iapi.sellerproduct.testcase;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellerproduct.service.SysActivityProductCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AssertService;
import com.ymttest.business.service.SellerProductCallService;
import com.ymttest.database.mongo.ProductActivityInfoWapper;
import com.ymttest.utils.EnvSetup;

public class Ts_SysActivityProduct {
	private static String sellerName = EnvSetup.getData("productsellername");
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	
	private static String activityNotStartId = EnvSetup.getData("productActivityNotStartId");
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("同步活动信息");
	}

	@Before
	public void caseUp() {
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(new SysActivityProductCall().getOpurl());
	}
	
	
	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SysActivityProduct() {
		Logger.start(true, "同步活动信息");
		try{
			String activityName = "testAuto";
			int activityId = 19073;
			
			//1 add new product
			String productId = SellerProductCallService.addNewProductNotOnSale(sellerId,sellerName,null).getJSONObject("Data").getString("ProductID");
			
			//2 sys activity product
			Map<String, Object> updateMap = new HashMap<String,Object>();
			updateMap.put("ActivityProductInfos[0]->ProductId", productId);
			updateMap.put("ActivityProductInfos[0]->ActivityId", activityId);
			updateMap.put("ActivityProductInfos[0]->ActivityName", activityName);
			
			JSONObject requestBean =  new SysActivityProductCall().callAndGetReturnData(updateMap);
			Logger.verifyEquals( 200,requestBean.getInt("Code"), "响应报文-返回码");
			Logger.verifyEquals( true,requestBean.getJSONObject("Data").getBoolean("SysActivityProductSuccess"), "响应报文-Data");
			
			// check mongo
			Map<String, Object> productActivityInfoBean = new ProductActivityInfoWapper().getByProductId(productId);
			Map<String, Object> tgtRetMap = new HashMap<String,Object>();
			tgtRetMap.put("ActivityName", activityName);
			tgtRetMap.put("ActivityId", activityId);
			tgtRetMap.put("ProductId", productId);
			AssertService.assertResultEqual(tgtRetMap, productActivityInfoBean);
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
}
